/**
 * @file       IEvent.h
 * @brief      Base class for all events of the Framework
 * @author     Huabo Zheng
 * @date       Jan 13, 2012
 * @Copyright  2012, www.netgear.com Inc. All rights reserved.
 */

#ifndef IEVENT_H_
#define IEVENT_H_
#include <ctime>
#include "Point.h"
#include "typedefine.h"
#include "Object.h"

namespace NS_LCD_AFW
{

class CFrame;
/**
 *NS_LCD_AFW::IEvent
 */

/**
 *@class  IEvent
 *@brief  Base class for all events of the Framework
 */
class IEvent
{
public:

	/**
	 *@brief Constructor
	 *@attention This objects can only be create in the heap memory and call destroy() for destruction
	 *@see destory
	 */
	IEvent();

protected:

	/**
	*@brief DeConstructor
	*@attention This objects can only be create in the heap memory and call destroy() for destruction
	*@see destory()
	*/
	virtual ~IEvent();
public:

	/**
	 * @typedef int Param
	 */
	typedef int Param;

	/**
	 * @enum EventType
	 */
	enum EventType
	{
		NOTIFY_EVENT, ///< NOTIFY_EVENT  means when an Event has be processed successfully by a event handler,then it will be destory
		BROADCAST_EVENT ///< BROADCAST_EVENT means all of the event handlers will process the event
	};

	/**
	* @enum EventCode
	* @see int CFrame::postEvent(int eventId, int param)
	* @see int CFrame::postEvent(CAppEvent *pEvent)
	*/
	enum EventCode
	{
		UN_KNOW_EVENT_CODE,  ///< Un know event code,it means that the event may not be processed by the framework
		KEYBOARD_EVENT_CODE,///<  It specific the event is a keyboard event
		APP_EVENT_CODE,     ///< It specific the event is a app event . user can raise the event by invoke CFrame::postEvent(int eventId, int param) or CFrame::postEvent(CAppEvent *pEvent);
		APP_EXIT_EVENT_CODE  ///< APP_EXIT_EVENT_CODE,when framework receives this event,the application will exit friendly
		/*
	 REPAINT_EVENT_CODE,
	 REPAINT_RECT_EVENT_CODE,
	 GET_FOCUS_EVENT_CODE,
	 LOST_FOCUS_EVENT_CODE,
	 GET_HIGHTLIGHT_EVENT_CODE,
	 LOST_HIGHTLIGHT_EVENT_CODE,
	 */
	};
public:

	/**
	 *@brief  Commissioned by the event processing
	 *@details The functino will only be called by framework while user not hook the message chain by rewriting CEventHandler::handlerEvent()
			   and not register callback by call CEventHandler::registerCallBack
	 *@param[in]  pFrameEventHandler A pointer to a CFrame object
	 *@exception none
	 *@retval    int
	 *@return    ERR_SUCCESS if successful,otherwise failure
	 *@note
	 *@attention
	 *@see int IEventListener::actionPerformed(IEvent *pEvent)
	 *@see void CEventHandler::registerCallBack(int eventId, AFW_EventCallBack pCallBack)
	*/
	virtual int doProcess(CFrame *pFrameEventHandler) = 0;

public:

	/**
	 *@brief Get event param
	 *@details When an event happens, user can bind the event a parameter,user can get the param again by rewriting CEventHandler::handlerEvent() and processes it if necessary
	 *@exception none
	 *@retval    Param
	 *@return    User predefined parameter
	 *@note
	 *@attention
	 *@see       int CEventHandler::handlerEvent(IEvent *pEvent)
	 */
	Param getParam() const;

	/**
	 *@brief Get event code
	 *@details Get event code
	 *@exception none
	 *@retval    EventCode
	 *@return    Event code
	 *@note
	 *@attention
	 *@see       EventCode
	 */
	EventCode getCode() const;

	/**
	 *@brief Get event Id
	 *@details Get event Id
	 *@exception none
	 *@retval    int
	 *@return    Event id
	 *@note
	 *@attention
	 *@see
	 */
	int getEventId() const;

	/**
	 *@brief Get event type
	 *@details Get event Id
	 *@exception none
	 *@retval    EventType
	 *@return    Event type
	 *@note
	 *@attention
	 *@see      EventType
	 */
	EventType getType() const;

	/**
	 *@brief Get event occurs time
	 *@details Get event occurs time, accurate to the millisecond
	 *@exception none
	 *@retval    time_t
	 *@return    Event occurs time, accurate to the millisecond
	 *@note
	 *@attention
	 *@see
	 */
	time_t getOccurTime() const;

	/**
	 *@brief Get cursor position while event occurs
	 *@details Get cursor position while event occurs
	 *@exception none
	 *@retval    CPoint
	 *@return    Cursor position while event occurs
	 *@note
	 *@attention
	 *@see       CPoint()
	 */
	CPoint getPoint() const;

	/**
	 *@brief  Set event param
	 *@details Set event param
	 *@param[in]  eventParam
	 *@exception none
	 *@retval    void
	 *@return    none
	 *@note      none
	 *@attention none
	 *@see
	*/
	void setParam(Param eventParam);

	/**
	 *@brief  Set event type
	 *@details Set event type
	 *@param[in]  nEventType
	 *@exception none
	 *@retval    void
	 *@return    none
	 *@note      none
	 *@attention none
	 *@see
	*/
	void setType(EventType nEventType);

	/**
	 *@brief  Set event id
	 *@details Set event id
	 *@param[in]  nEventId
	 *@exception none
	 *@retval    void
	 *@return    none
	 *@note      none
	 *@attention none
	 *@see
	*/
	void setEventId(int nEventId);

public:
	/**
	 *@brief  Destory the event object
	 *@details  Destory the event object
	 *@exception none
	 *@retval    void
	 *@return    none
	 *@note      none
	 *@attention user must call destroy() for destruction
	 *@see
	*/
	void destory();
protected:

	/**
	 *@brief  Set event code
	 *@details Set event code
	 *@param[in]  eventCode
	 *@exception none
	 *@retval    void
	 *@return    none
	 *@note      none
	 *@attention Eventcode had already identified when design class,so user can't change it anymore outside in runtime
	 *@see
	*/
	void setCode(EventCode eventCode);

	/**
	 *@brief  Set event Occur Time
	 *@details Set event Occur Time
	 *@param[in]  nOccurTime
	 *@exception none
	 *@retval    void
	 *@return    none
	 *@note      none
	 *@attention Event Occur Time had already identified when class is instantiated,so user can't change it anymore outside
	 *@see
	*/
	void setOccurTime(time_t nOccurTime);

	/**
	 *@brief  set current cursor position while event occurs
	 *@details set current cursor position while event occurs
	 *@param[in]  point  Current cursor position
	 *@exception none
	 *@retval    void
	 *@return    none
	 *@note      none
	 *@attention The  cursor position had already identified when class is instantiated,so user can't change it anymore outside
	 *@see
	*/
	void setPoint(CPoint point);

private:
	void init();
private:
	EventType m_nEventType; ///< event type
	EventCode m_nEventCode; ///< event code
	int m_nEventId;         ///< event id
	Param m_eventParam;     ///< event param
	time_t m_nOccurTime;    ///< event occurs time
	CPoint m_point;         ///< current cursor position while event occurs

private:
	DISABLE_COPY_CONSTRUCTOR_AND_ASSIGN_REFERENCE(IEvent);

};

} /* namespace NS_LCD_AFW */
#endif /* IEVENT_H_ */
